com.cete.dynamicpdf.merger
Class Attachment



Example : The following examples retrieves the attachment files in the PDFDocument.
   import com.cete.dynamicpdf.*;
   import com.cete.dynamicpdf.merger.*;
   import java.io.FileNotFoundException;
   import java.io.FileOutputStream;
   import java.io.IOException;
 
   public class MyClass {
     public static void main(String args[]) {
         // Create PDF document object
         PdfDocument pdfA = new PdfDocument("[physicalpath]/ImportPDF.pdf");

         // Merge the PDF document
         MergeDocument mergeDocument = new MergeDocument(pdfA);

         // Getting the AttachmentFiles present in PDFDocument
         Attachment[] attachments = pdfA.getAttachments();

         // Looping through the files to get Attachment Files present
         String outputPath = "[physicalpath]";
         for (Attachment file : attachments) {
             FileOutputStream stream = null;
             try {
                 byte[] file1 = file.getData();
                 stream = new FileOutputStream(outputPath + file.getFilename());
 
                 try {
                     stream.write(file1);
                 } catch (IOException ex) {
                     System.out.println("An IOException was caught :"+ ex.getMessage());
                 }

             } catch (FileNotFoundException ex) {    
                 System.out.println("File does not exist.");
             } finally {
                 try {
                     stream.close();
                 } catch (IOException ex) {   
                     System.out.println("An IOException was caught :"+ ex.getMessage());
                 }
             }
         }
         // Save the PDF
         mergeDocument.draw("[Physicalpath]/MyDocument.pdf");
      }
    }